home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / BAR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.1 KB  |  46 lines

  1.                                             /* bar.c */
  2.                                  /* Entered by A. Wayner */
  3.  
  4. # include <graphics.h>
  5. # include <stdlib.h>
  6.  
  7. main()
  8. {
  9.     int graphdriver = DETECT;
  10.     int graphmode, i;
  11.     int data[5] = {2, 1, 3, 5, 4 }, maxdata = 5, numpt = 5;
  12.     int maxheight, maxwidth, xstep, ystep, x, y, maxcolor;
  13.  
  14.  
  15.                                             /* Detect adapter type and    */
  16.                                             /* initialize graphics system */
  17.       initgraph( &graphdriver, &graphmode, "\\turboc");
  18.     outtextxy( 10, 10, "Bar graphs using 'bar' ");
  19.  
  20.                                             /* Now draw the bar graph */
  21.     maxheight = getmaxy() - 100;
  22.     ystep = maxheight / maxdata;
  23.  
  24.     maxwidth = getmaxx() - 200;
  25.     xstep = maxwidth / numpt;
  26.  
  27.     x = 100;
  28.     y = maxheight + 40;
  29.  
  30.                                             /* Use random color */
  31.     randomize();
  32.     maxcolor = getmaxcolor();
  33.     for( i = 0; i < numpt; i++, x += xstep )
  34.     {
  35.         setfillstyle( (i % 11) + 1, random( maxcolor ) );
  36.         bar( x, y - data[i] * ystep, x + xstep, y );
  37.     }
  38.                                             /* Wait until user presses a key */
  39.     outtextxy( 10, getmaxy() - 30," Press any key to exit");
  40.  
  41.  
  42.     getch();                                /* Wait until a key is pressed */
  43.     closegraph();                        /* Exit graphics library */
  44.  
  45. }
  46.